<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../commons/commons.jsp"%>
<!DOCTYPE html>

<head>
    <meta charset="utf-8" />
    <title>Data Tables</title>
    <link href="${ctx }/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
</head>
<body>
<div class="page-body">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="widget">
                <div class="widget-body">
                    <form id="saveOrUpdate" class="form-horizontal form-bordered" role="form" enctype="multipart/form-data" method="post" action="${ ctx}/service/update.do">
                    	<input type="hidden" id = "id" name="id" value="${bean.id }"/>
                    		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">服务名称</label>
	                        	<div class="col-sm-2">
	                        		<input type="text" class="form-control" id="serviceName" name="serviceName"   value = "${bean.serviceName}"
	                        				placeholder="服务名称" data-bv-notempty="true" data-bv-notempty-message="服务名称不能为空" />
	                        	</div>
                       		</div>
                    		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">图标</label>
	                        	<div class="col-sm-10">
	                        		<img src="${bean.imgUrl }" style="width:100px;height:100px" />
	                        		<input id="labelfile" type="file" name="labelfile" required="required" class="file nannyuser" data-show-upload="false"/>
	                        	</div>
                        	</div>
                    		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">文字描述</label>
	                        	<div class="col-sm-10">
	                        		<input type="text" class="form-control" id="serviceDescribe" name="serviceDescribe"   value = "${bean.serviceDescribe}"
	                        				placeholder="文字描述" data-bv-notempty="true" data-bv-notempty-message="文字描述不能为空" />
	                        	</div>
                       		</div>
                       		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">平均薪水</label>
	                        	<div class="col-sm-10">
	                        		<input type="text" class="form-control" id="avgSalary" name="avgSalary"   value = "${bean.avgSalary}"
	                        				placeholder="平均薪水" data-bv-notempty="true" data-bv-notempty-message="平均薪水不能为空" />
	                        	</div>
                       		</div>
                       		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">基本计费单位</label>
	                        	<div class="col-sm-3">
	                        		<select id="unit" name="unit" class="form-control" required="required">
      									<option value="月">月</option>
      									<option value="小时">小时</option>
      								</select>
	                        	</div>
                       		</div>
                       		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">优惠套餐一(预约3个月优惠)</label>
	                        	<div class="col-sm-2">
	                        		<input type="text" class="form-control" id="discount1" name="discount1"   value = "${bean.discount1}"
	                        				placeholder="优惠套餐一" data-bv-notempty="true" data-bv-notempty-message="优惠套餐一不能为空" />
	                        	</div>
                       		</div>
                       		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">优惠套餐二(预约半年优惠)</label>
	                        	<div class="col-sm-2">
	                        		<input type="text" class="form-control" id="discount2" name="discount2"   value = "${bean.discount2}"
	                        				placeholder="优惠套餐二" data-bv-notempty="true" data-bv-notempty-message="优惠套餐二不能为空" />
	                        	</div>
                       		</div>
                       		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">优惠套餐三(预约一年优惠)</label>
	                        	<div class="col-sm-2">
	                        		<input type="text" class="form-control" id="discount3" name="discount3"   value = "${bean.discount3}"
	                        				placeholder="优惠套餐三" data-bv-notempty="true" data-bv-notempty-message="优惠套餐三不能为空" />
	                        	</div>
                       		</div>
                       		<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">选择颜色</label>
	                        	<div class="col-sm-2 input-group colorpicker-element">
	                        		<input type="text" name="color" class="form-control" value="#e24f43" />
	                        		<span class="input-group-addon"><i></i></span>
	                        	</div>
                       		</div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <a class="btn btn-palegreen" href="javascript:save()">提交</a>
                                <a class="btn btn-palegreen" href="${ctx}/service/list.do">返回</a>
                            </div>
                     	</div>
                 	</form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<!-- Color picker -->
<script src="${ctx }/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script>
	$(document).ready(function () {
	    $('#picUpload').bootstrapValidator();
	});
	
	$('.colorpicker-element').colorpicker();
	
	$("#unit option:contains('${bean.unit}')").attr("selected", true);
	var pattern = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/; 
	var save =function(){
		if(!$.trim($('#serviceDescribe').val())){
			warningAlert("文字描述不能为空");
			return;
		}
		if(!$.trim($('#serviceName').val())){
			warningAlert("服务名称不能为空");
			return;
		}
		if(!$.trim($('#avgSalary').val())){
			warningAlert("平均薪水不能为空");
			return;
		}
		if(!pattern.test($('#avgSalary').val())){
			warningAlert("平均薪水请输入数字");
			return;
		}
		if(!$.trim($('#discount1').val())){
			warningAlert("优惠套餐一不能为空");
			return;
		}
		if(!pattern.test($('#discount1').val())){
			warningAlert("优惠套餐一请输入数字");
			return;
		}
		if(!$.trim($('#discount2').val())){
			warningAlert("优惠套餐二不能为空");
			return;
		}
		if(!pattern.test($('#discount2').val())){
			warningAlert("优惠套餐二请输入数字");
			return;
		}
		if(!$.trim($('#discount3').val())){
			warningAlert("优惠套餐三不能为空");
			return;
		}
		if(!pattern.test($('#discount3').val())){
			warningAlert("优惠套餐三请输入数字");
			return;
		}
	
	$(".page-body").block({
               	message: "<img src='${ctx}/img/loading.gif' style='width:25px;height:25px'></img><h4>处理中,请稍后...</h4>"
            });
		$("#saveOrUpdate").ajaxSubmit(function(result) {
			  if(result.status == 1){
				  window.location.href = '${ctx}' + "/service/list.do";
			  }else{
				  warningAlert(result.message[0].msg);
				  $(".page-body").unblock();
			  }
		});
	}
</script>
</html>
